package org.springblade.common.utils.delayed;

import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import com.github.thierrysquirrel.annotation.CommonMessage;
import com.github.thierrysquirrel.annotation.RocketMessage;
import com.github.thierrysquirrel.annotation.StartDeliverTime;
import com.github.thierrysquirrel.core.producer.MessageSendType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.Date;

/**
 * User: Jackey
 * Date: 2019/11/27
 * Time: 下午2:17
 * Description:
 */

@Slf4j
@Component
@RocketMessage(groupID = "GID_delayed")
public class DelayedSend {

//	/**
//	 * 生产延迟消息到MQ
//	 * @param startDeliverTime 时间戳(毫秒),不能小于当前时间
//	 * @param message 消息体
//	 * @return
//	 */
//    @CommonMessage(topic = "delayed", tag = "delayed",messageSendType = MessageSendType.SEND_ASYNC)
//    public String sendDelayed(@StartDeliverTime long startDeliverTime, String message) {
//        log.info("===============延时队列生产消息====================",startDeliverTime);
//        log.info("发送时间:[{}],发送内容:[电梯编码:{}]", LocalDateTime.now(), message);
//        return message;
//    }
//
//	/**
//	 * 生产实时消息到MQ
//	 * @param message 消息体
//	 * @return
//	 */
//	@CommonMessage(topic = "delayed", tag = "message",messageSendType = MessageSendType.SEND_ASYNC)
//	public String sendMsg(@StartDeliverTime long startDeliverTime,String message) {
//		log.info("===============实时生产消息====================", System.currentTimeMillis());
//		log.info("发送时间:[{}],发送内容:[项目关联申请消息:{}]", LocalDateTime.now(), message);
//		return message;
//	}

	/**
	 * 发送救援到达即将到时消息
	 * @param message 消息体
	 * @return
	 */
	@CommonMessage(topic = "delayed_test", tag = "rescue_arrive_test",messageSendType = MessageSendType.SEND_ASYNC)
	public String sendRescueMsg(@StartDeliverTime long startDeliverTime,String message) {
		log.info("===================================", System.currentTimeMillis());
		log.info("发送时间:[{}],延迟时间:[{}],发送内容:[救援工单信息:{}]", LocalDateTime.now(), DateUtil.format(new Date(startDeliverTime), "yyyy-MM-dd HH:mm:ss"), message);
		return message;
	}

	/**
	 * 发送救援到达超时消息
	 * @param message 消息体
	 * @return
	 */
	@CommonMessage(topic = "delayed", tag = "rescue_arrive",messageSendType = MessageSendType.SEND_ASYNC)
	public String sendRescueArriveMsg(@StartDeliverTime long startDeliverTime,String message) {
		log.info("===============实时生产消息====================", System.currentTimeMillis());
		log.info("发送时间:[{}],延迟时间:[{}],发送内容:[救援工单信息:{}]", LocalDateTime.now(), DateUtil.format(new Date(startDeliverTime), "yyyy-MM-dd HH:mm:ss"), message);
		return message;
	}

}
